package chpt_06_01_observer;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Ping
 * @date 2023/5/4 11:12
 **/
public class ObeserverDemo {
    JButton button ;
    Container container ;



}

/**
 * Subject
 */
class Cat {
    private List<CatCryRelatedAnimal> animals = new ArrayList<>();

    /**
     * managing related animals
     * @param animal
     */
    public void attach(CatCryRelatedAnimal animal) {
        this.animals.add(animal) ;
    }
    public void detach(CatCryRelatedAnimal animal) {

    }
    public void cry() {
        System.out.println("Cat was crying!") ;
        for (CatCryRelatedAnimal animal : this.animals) {
            animal.response();
        }
    }
}

/**
 * Obeserver:
 */
interface CatCryRelatedAnimal {
    public void response() ;
}
class Dog implements CatCryRelatedAnimal {
    @Override
    public void response() {
        System.out.println("Doy was crying too!") ;
    }
}

class Mouse implements CatCryRelatedAnimal {
    @Override
    public void response() {
        System.out.println("Mouse was fearing and fleeting !") ;
    }
}
